package com.loe.ktui.custom

import android.content.Context
import android.view.ViewGroup
import androidx.drawerlayout.widget.DrawerLayout
import com.loe.ktui.UiGroup

open class UiDrawerLayout(id: String? = null) : UiGroup(id)
{
    open fun initUI(context: Context, view: DrawerLayout)
    {
        super.initUI(context, view)

        isAlphaClick?.let { view.isClickable = true }

        // 递归子元素
        childs.forEach()
        {
            it.createView(context, view)
        }
    }

    /** 创建view */
    override fun createView(context: Context, parent: ViewGroup?): DrawerLayout
    {
        return DrawerLayout(context).also()
        {
            initUI(context, it)
            addToParent(parent, it)
        }
    }
}

fun Any.ui_DrawerLayout(id: String? = null, block: (UiDrawerLayout.() -> Unit)? = null): UiDrawerLayout
{
    val ui = UiDrawerLayout(id)
    block?.let { ui.it() }
    if (this is UiGroup) addChild(ui)
    return ui
}